<#include '/admin/header.html' >
<#assign dateFormat="com.enation.framework.directive.DateformateDirective"?new()>
<div id="loading"></div>
<div  class="admin-main">
   <div>
    	<!-- 提示区域 -->
        <div class="page_explain">
            <h2>操作提示</h2>
            <ul>
                <li><span>·</span>上架状态分为：是、否,两种状态</li>
                <li><span>·</span>可以对商品进行删除，或者还原操作，恢复商品到正常商品列表，进行相关操作。</li>
            </ul>
        </div>
   </div>
        <!-- 按钮操作 -->
   <form id="goodsform" method="post">
        <div class="table_control">
            <div class="table_opera">
                <button type="button" title="清除" id="cleanBtn"  class="layui-btn layui-btn-primary layui-btn-small" onclick="cleargoods()"><i class="layui-icon">&#xe640;</i></button>
                <button type="button" title="还原" id="revertBtn" class="layui-btn layui-btn-primary layui-btn-small" onclick="revertgoods()"><i class="layui-icon">&#xe603;</i></button>
                <button type="button" title="提示" class="layui-btn layui-btn-primary layui-btn-small" id="explain"><i class="layui-icon">&#xe607;</i></button>
            </div>
        </div>
   <!--表格区域  -->
    	<table id="goodsdata" class="layui-table site-table table-hover" >
        	<thead>
        	<tr>
            	<th><input type='checkbox'  class='btn-checkall fly-checkbox' id='selected-all'></th>
            	<th>商品编号</th>
            	<th>商品名称</th>
            	<th>分类</th>
            	<th>销售价格</th>
            	<th>上架</th>
            	<th>品牌</th>
            	<th>上架时间</th>
            	<th>操作</th>
        	</tr>
        	</thead>
    	</table>
    <!-- 传值等区域(暂定) -->
    	<div id="addBrand" ></div>
   </form>
</div>

<!--js区域  -->
<script>
var table;
$(function(){
	
	table = $('#goodsdata').DataTable({
		"language": {
	        "url": "${staticserver}/media/zh_CN.txt"
	    },
	    "processing": true,
	    "serverSide": true,
	    "ordering": false,
	    "searching": false,
	    "lengthChange": false,
	    ajax: {
	        //指定数据源
	        type:"post",
	        url: '${ctx}/shop/admin/goods/trash-list-json.do',
	    },
	    columns: [ //定义列
            {"data": function (obj) {
                return '<input type="checkbox" name="goods_id" class="fly-checkbox" value=' + obj.goods_id + '>';
            		}},
	        {data: "sn"},
	        {data: "name"},
	        {data: "cat_name"},
	        {data: "price"},
	        {data: null,"render": function(data,type,row){
	        	return market_enable(data.market_enable,type,row);
	        }},
	        {data: "brand_name"},
	        {data: function(s_time) {
   	        	if(s_time.last_modify==null){
   	        		return " ";
   	        	}else{
   	        		return  getFormatDateByLong(s_time.last_modify, "yyyy-MM-dd");
   	        	}
   	       	}},
	        {data: null,"render": function(data, type, row) {
	        	return "<a class='layui-btn layui-btn-small _aa' name='change_btn' onclick='del("+row.goods_id+")'>删除</a>";		
	       	}}
	     ]
	});
	
});

function cleargoods(){
	var ch_goodsId = $("input[name='goods_id']").is("input:checked");
	if(ch_goodsId == false){
		alert("请选择要清除的商品");
		return false;
	}
	if (!confirm("确定要清除这些商品吗？")) {
		return;
	}
	var options = {
			url:ctx+"/shop/admin/goods/clean.do",
			type:"post",
			dataType:"json",
			success:function(data){
				if(data.result==1){
					$.Loading.success(data.message);
					table.ajax.url(ctx+"/shop/admin/goods/trash-list-json.do").load();
				}
			}
	};
	$("#goodsform").ajaxSubmit(options);
}

function revertgoods(){
	var ch_goodsId = $("input[name='goods_id']").is("input:checked");
	if(ch_goodsId == false){
		alert("请选择要还原的商品");
		return false;
	}
	if (!confirm("确定要还原这些商品吗？")) {
		return;
	}
	var options = {
			url:ctx+"/shop/admin/goods/revert.do",
			type:"post",
			dataType:"json",
			success:function(data){
				if(data.result==1){
					$.Loading.success("还原成功");
					table.ajax.url(ctx+"/shop/admin/goods/trash-list-json.do").load();
				}
			}
	};
	$("#goodsform").ajaxSubmit(options);
}
function market_enable(value,row,index){
	var val;
	if(value==1){val="是";}else if(value==0){val="否";}
	return val;
} 

function del(goods_id){
	var options = {
		url : "${ctx}/shop/admin/goods/clean.do?ajax=yes&goods_id="+goods_id,
		type : "POST",
		dataType : 'json',
		success : function(result) {
			if (result.result == 1) {
				$.Loading.success(result.message);
				//$('#goodsdata').datagrid("reload");
				location.reload();
			}
			if (result.result == 0) {
				$.Loading.error(result.message);
			}
			$("#cleanBtn").linkbutton("enable");
		},
		error : function(e) {
			$.Loading.error("出现错误 ，请重试");
			$("#cleanBtn").linkbutton("enable");
		}
	};
	$('#goodsform').ajaxSubmit(options);
}

</script>
<#include '/admin/footer.html' >